using QuanLyThongTinCoSo.Forms.CanBoQuanLy;
using QuanLyThongTinCoSo.Forms.CapQuanLyHanhChinh;
using QuanLyThongTinCoSo.Forms.CoQuanCapVanBanThamDuyet;
using QuanLyThongTinCoSo.Forms.CoQuanQuanLyPCCC;
using QuanLyThongTinCoSo.Forms.Doi;
using QuanLyThongTinCoSo.Forms.HinhThucDauTu;
using QuanLyThongTinCoSo.Forms.LoaiHinhHoatDong;
using System;
using System.Windows.Forms;
using QuanLyThongTinCoSo.Forms.NhomPhuongTien;
using QuanLyThongTinCoSo.Forms.NganhOrLinhVuc;
using QuanLyThongTinCoSo.Forms.PhanLoaiChiTietPhuongTien;
using QuanLyThongTinCoSo.Forms.PhieuDieuTraCoSo;
using QuanLyThongTinCoSo.Forms.Phong;
using QuanLyThongTinCoSo.Forms.PhuongTien;
using QuanLyThongTinCoSo.Forms.Role;
using QuanLyThongTinCoSo.Forms.ThanhPhanKinhTe;
using QuanLyThongTinCoSo.Forms.User;
using QuanLyThongTinCoSo.Forms.LoaiCoSo;
using QuanLyThongTinCoSo.Forms.VanBanThamDuyet;
using QuanLyThongTinCoSo.Forms.ThoiDiem;

namespace QuanLyThongTinCoSo.Forms
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        #region ShowBackground

        private void ShowBackground()
        {
            pbBackground.Visible = false;
        }

        #endregion

        #region Closed

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            while (Application.OpenForms.Count > 0)
            {
                Application.OpenForms[0].Close();
            }
        }

        #endregion

        #region Phieu Dieu Tra Co So

        private void mnuItemPhieuDieuTraCoSo_Click(object sender, EventArgs e)
        {
            LoadPhieuDieuTraCoSo();
            //PhieuDieuTraCoSoDetailShow();
        }

        private void PhieuDieuTraCoSoDetailShow()
        {
            ShowBackground();
            var frm = Application.OpenForms["frmPhieuDieuTraCoSoDetail"] as frmPhieuDieuTraCoSoDetail;
            if (frm != null)
            {
                frm.WindowState = FormWindowState.Maximized;
                frm.BringToFront();
                frm.Activate();
            }
            else
            {
                frm = new frmPhieuDieuTraCoSoDetail {MdiParent = this, WindowState = FormWindowState.Maximized};
                frm.MdiParent = this;
                frm.Show();
            }
            lblStatus.Text = "Phiếu điều tra cơ sở";
        }

        private void LoadPhieuDieuTraCoSo()
        {
            ShowBackground();
            var frm = new frmPhieuDieuTraCoSoList { MdiParent = this, WindowState = FormWindowState.Maximized };
            frm.Show();
            lblStatus.Text = "Danh sách phiếu điều tra cơ sở";
        }

        private void MnuItemPhieuDieuTraCoSoList_Click(object sender, EventArgs e)
        {
            LoadPhieuDieuTraCoSo();
        }

        private void mnuButtonPhieuDieuTraCoSo_Click(object sender, EventArgs e)
        {
            PhieuDieuTraCoSoDetailShow(); 
        }

        #endregion

        #region Phong

        private void mnuItemPhong_Click(object sender, EventArgs e)
        {
            LoadPhong();
        }

        private void LoadPhong()
        {
            ShowBackground();
            var frm = Application.OpenForms["frmPhongList"] as frmPhongList;
            if (frm != null)
            {
                frm.WindowState = FormWindowState.Maximized;
                frm.BringToFront();
                frm.Activate();
            }
            else
            {
                frm = new frmPhongList {MdiParent = this, WindowState = FormWindowState.Maximized};
                frm.MdiParent = this;
                frm.Show();
            }
            lblStatus.Text = "Phòng";
        }

        private void btnPhong_Click(object sender, EventArgs e)
        {
            LoadPhong();
        }

        #endregion

        #region Đơn vị

        private void mnuItemDonVi_Click(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = Application.OpenForms["frmDoiList"] as frmDoiList;
            if (frm != null)
            {
                frm.WindowState = FormWindowState.Maximized;
                frm.BringToFront();
                frm.Activate();
            }
            else
            {
                frm = new frmDoiList {MdiParent = this, WindowState = FormWindowState.Maximized};
                frm.MdiParent = this;
                frm.Show();

                lblStatus.Text = "Đội";
            }
        }

        private void LoadDoi()
        {
        }

        private void btnDoi_Click(object sender, EventArgs e)
        {
        }

        #endregion

        #region Cán bộ quản lý

        private void mnuItemCanBo_Click(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = Application.OpenForms["frmUserList"] as frmUserList;
            if (frm != null)
            {
                frm.WindowState = FormWindowState.Maximized;
                frm.BringToFront();
                frm.Activate();
            }
            else
            {
                frm = new frmUserList {MdiParent = this, WindowState = FormWindowState.Maximized};
                frm.MdiParent = this;
                frm.Show();
            }
            lblStatus.Text = "Cán bộ quản lý";
        }

        #endregion

        #region Cấp quản lý hành chính

        private void mnuCapQuanLyHanhChinh_Click(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = Application.OpenForms["frmCapQuanLyHanhChinhList"] as frmCapQuanLyHanhChinhList;
            if (frm != null)
            {
                frm.WindowState = FormWindowState.Maximized;
                frm.BringToFront();
                frm.Activate();
            }
            else
            {
                frm = new frmCapQuanLyHanhChinhList {MdiParent = this, WindowState = FormWindowState.Maximized};
                frm.MdiParent = this;
                frm.Show();
            }
            lblStatus.Text = "Cấp quản lý hành chính";
        }

        #endregion

        #region Cơ quan quản lý PCCC

        private void mnuItemCoQuanQuanLyPCCC_Click(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = Application.OpenForms["frmCoQuanQuanLyPCCCList"] as frmCoQuanQuanLyPCCCList;
            if (frm != null)
            {
                frm.WindowState = FormWindowState.Maximized;
                frm.BringToFront();
                frm.Activate();
            }
            else
            {
                frm = new frmCoQuanQuanLyPCCCList {MdiParent = this, WindowState = FormWindowState.Maximized};
                frm.MdiParent = this;
                frm.Show();
            }
            lblStatus.Text = "Cơ quan quản lý PCCC";
        }

        #endregion

        private void mnuItemHinhThucDauTu_Click(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = Application.OpenForms["frmHinhThucDauTuList"] as frmHinhThucDauTuList;
            if (frm != null)
            {
                frm.WindowState = FormWindowState.Maximized;
                frm.BringToFront();
                frm.Activate();
            }
            else
            {
                frm = new frmHinhThucDauTuList {MdiParent = this, WindowState = FormWindowState.Maximized};
                frm.MdiParent = this;
                frm.Show();
            }
            lblStatus.Text = "Hình thức đầu tư";
        }

        private void mnuItemThanhPhanKinhTe_Click(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = Application.OpenForms["frmThanhPhanKinhTeList"] as frmThanhPhanKinhTeList;
            if (frm != null)
            {
                frm.WindowState = FormWindowState.Maximized;
                frm.BringToFront();
                frm.Activate();
            }
            else
            {
                frm = new frmThanhPhanKinhTeList {MdiParent = this, WindowState = FormWindowState.Maximized};
                frm.MdiParent = this;
                frm.Show();
            }
            lblStatus.Text = "Thành phần kinh tế";
        }

        private void ViewRole(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = new frmRoleList {MdiParent = this, WindowState = FormWindowState.Maximized};
            frm.Show();
            lblStatus.Text = "Quyền";
        }

        private void mnuInfo_Click(object sender, EventArgs e)
        {
            var frm = new frmInformation();
            frm.ShowDialog();
        }

        private void mnuItemCanBoQuanLy_Click(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = Application.OpenForms["frmCanBoQuanLyList"] as frmCanBoQuanLyList;
            if (frm != null)
            {
                frm.WindowState = FormWindowState.Maximized;
                frm.BringToFront();
                frm.Activate();
            }
            else
            {
                frm = new frmCanBoQuanLyList {MdiParent = this, WindowState = FormWindowState.Maximized};
                frm.MdiParent = this;
                frm.Show();
            }
            lblStatus.Text = "Cán bộ quản lý";
        }

        private void mnuItemLoaiHinhHoatDong_Click(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = new frmLoaiHinhHoatDongList {MdiParent = this, WindowState = FormWindowState.Maximized};
            frm.Show();
            lblStatus.Text = "Loại hình hoạt động";
        }

        private void mnuItemNganhLinhVuc_Click(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = new frmNganhOrLinhVucCoSoList {MdiParent = this, WindowState = FormWindowState.Maximized};
            frm.Show();
            lblStatus.Text = "Ngành, lĩnh vực";
        }

        

        private void btnThoat_Click(object sender, EventArgs e)
        {
            foreach (Form openForm in Application.OpenForms)
            {
                openForm.Close();
            }
            Application.Exit();
        }

        private void ListLoaiPhuongTien(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = new frmNhomPhuongTienCoSoList { MdiParent = this, WindowState = FormWindowState.Maximized };
            frm.Show();
            lblStatus.Text = "Loại phương tiện";
        }

        private void ListPhuongTien(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = new frmPhuongTienList { MdiParent = this, WindowState = FormWindowState.Maximized };
            frm.Show();
            lblStatus.Text = "Phương tiện";
        }

        private void CloseMainForm(object sender, FormClosedEventArgs e)
        {
            while (Application.OpenForms.Count > 0)
            {
                Application.OpenForms[0].Close();
            }
        }

        private void mnuItemDangXuat_Click(object sender, EventArgs e)
        {
            var frm = new frmDangNhap();
            frm.Show();
            Hide();
        }

        private void mnuitemPhanLoaiChiTiet_Click(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = new frmPhanLoaiChiTietPhuongTienCoSoList { MdiParent = this, WindowState = FormWindowState.Maximized };
            frm.Show();
            lblStatus.Text = "Phân loại chi tiết phương tiện";
        }

        private void mnuItemDoiMatKhau_Click(object sender, EventArgs e)
        {
            var frm = new frmUserChangePassword();
            frm.ShowDialog();
        }

        private void ViewLoaiCoSo(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = Application.OpenForms["frmLoaiCoSoList"] as frmLoaiCoSoList;
            if (frm != null)
            {
                frm.WindowState = FormWindowState.Maximized;
                frm.BringToFront();
                frm.Activate();
            }
            else
            {
                frm = new frmLoaiCoSoList { MdiParent = this, WindowState = FormWindowState.Maximized };
                frm.MdiParent = this;
                frm.Show();
            }
            lblStatus.Text = "Loại cơ sở";
        }

        private void mnuItemVanBan_Click(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = new frmVanBanThamDuyetList { MdiParent = this, WindowState = FormWindowState.Maximized };
            frm.Show();
            lblStatus.Text = "Danh sách văn bản";
        }

        private void mnuItemCoQuanCapVanBan_Click(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = new frmCoQuanCapVanBanThamDuyetList { MdiParent = this, WindowState = FormWindowState.Maximized };
            frm.Show();
            lblStatus.Text = "Danh sách cơ quan cấp văn bản";
        }

        private void ViewThoiDiem(object sender, EventArgs e)
        {
            ShowBackground();
            var frm = new frmThoiDiemList { MdiParent = this, WindowState = FormWindowState.Maximized };
            frm.Show();
            lblStatus.Text = "Quản lý thông tin thời điểm cháy";
        }
    }
}